#!/usr/bin/env python
# -*- coding: utf-8 -*-
from common.ConfigUtil import config


class RedisOperate():
    """
        redis执行器
    """
    def __init__(self,db):
        import redis
        self.redis = redis.Redis(host=config.read("redis", "host"),
                                 port=config.read("redis", "port"),
                                 db=config.read("redis", "db"),
                                 password=config.read("redis", "password"))

    def get(self,key):
        """
        获取redis的key值
        :param key:
        :return:
        """
        return str(self.redis.get(key),encoding="utf-8")

    def set(self,key,value,ex=None,px=None,nx=None,xx=None):
        """
        设置redis的key值,可设置过期时间
        :param key:
        :param value:
        :param ex:
        :param px:
        :param nx:
        :param xx:
        :return:
        """
        self.redis.set(key,value,ex,px,nx,xx)

if __name__ == '__main__':
    print(RedisOperate(0).get("name"))
    RedisOperate(1).set("name","baba")